package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryServiceImpl categoryService;

    @GetMapping("/page")
    public Result getCategoryByquery(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryService.getCategoryByquery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }
    @PutMapping
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result updateCategoryStatus(Integer id, @PathVariable("status") Integer status) {
        categoryService.updateCategoryStatus(id, status);
        return Result.success();
    }

    @DeleteMapping
    public Result delByIds(Integer id) {
        categoryService.delById(id);
        return Result.success();
    }
    @GetMapping("list")
    public Result getListByType(Integer type) {
        List<Category> list = categoryService.getListByType(type);
        return Result.success(list);
    }
}
